/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bsk;

import java.io.*;
import java.math.BigInteger;
import java.security.KeyPair;
import java.util.logging.Level;
import java.util.logging.Logger;
import komunikaty.Kandydaci;

/**
 *
 * @author Lukasz
 */
public class KeyGen {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
//        //generowanie kluczy i moduĹ‚Ăłw
//        KeyPair keypair = SVoting.generateRSAKeyPair();
//        BigInteger E = SVoting.getPublicExponent(keypair);
//        BigInteger D = SVoting.getPrivateExponent(keypair);
//        BigInteger N = SVoting.getModul(keypair);
//        //DRUGIE KLUCZE
//        KeyPair KP = SVoting.generateRSAKeyPair();
//        BigInteger E2 = SVoting.getPublicExponent(KP);
//        BigInteger D2 = SVoting.getPrivateExponent(KP);
//        BigInteger N2 = SVoting.getModul(KP);
//        BigInteger[] Klucze = new BigInteger[6];
//        Klucze[0] = E;
//        Klucze[1] = D;
//        Klucze[2] = N;
//        Klucze[3] = E2;
//        Klucze[4] = D2;
//        Klucze[5] = N2;
//        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("Klucze.dat"));
//        oos.writeObject(Klucze);
//        oos.flush();
//        oos.close();
//        for (BigInteger bigInteger : Klucze) {
//            System.out.println(bigInteger);
//        }
        
        
        BigInteger[] klu = OdczytKluczy("Klucze.dat");
        for (BigInteger bigInteger : klu) {
            System.out.println(bigInteger);
        }
        
        
    }
    
    public static BigInteger[] OdczytKluczy(String file){
        ObjectInputStream ois = null;
        BigInteger[] klucze = null;
        try {
            ois = new ObjectInputStream(new FileInputStream(file));
            klucze = (BigInteger[]) ois.readObject();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(KeyGen.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(KeyGen.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                ois.close();
            } catch (IOException ex) {
                Logger.getLogger(KeyGen.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return klucze;
    }
}
